package com.ruoyi.web.controller.devicedata;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.domain.device.DeviceInfo;
import com.ruoyi.web.domain.warning.FactorInfo;
import com.ruoyi.web.domain.warning.WarningInsect;
import com.ruoyi.web.pojo.request.device.DeviceInfoRequest;
import com.ruoyi.web.pojo.request.devicedata.DeviceFactorDataRequest;
import com.ruoyi.web.pojo.request.insect.InsectCountDataRequest;
import com.ruoyi.web.pojo.request.insect.InsectListRequest;
import com.ruoyi.web.pojo.request.insect.InsectTopRequest;
import com.ruoyi.web.pojo.vo.devicedata.DeviceContrastDataVO;
import com.ruoyi.web.pojo.vo.devicedata.DeviceFactorDataVO;
import com.ruoyi.web.pojo.vo.devicedata.DevicePhotoVO;
import com.ruoyi.web.pojo.vo.insect.HearderInsectVO;
import com.ruoyi.web.pojo.vo.insect.InsectAnalysisCountVO;
import com.ruoyi.web.pojo.vo.insect.InsectTopVO;
import com.ruoyi.web.service.device.DeviceInfoService;
import com.ruoyi.web.service.insect.InsectSituationService;
import com.ruoyi.web.service.warning.WarningInsectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "数据分析",tags = "数据分析")
@RestController
@RequestMapping("/insect-situation")
public class InsectSituationController {

    @Autowired
    private InsectSituationService insectSituationService;

    @Autowired
    private WarningInsectService warningInsectService;

    @Autowired
    private DeviceInfoService deviceInfoService;

    @ApiOperation("查询识虫排名")
    @GetMapping("/getInsectTop")
    public R getInsectTop(InsectTopRequest request)
    {
        List<InsectTopVO> tops = insectSituationService.getInsectTop(request);
        return R.ok(tops);
    }

    @ApiOperation("查询昆虫分类")
    @GetMapping("/getInsectList")
    public R getInsectList(InsectListRequest request)
    {
        List<WarningInsect> warningInsects = warningInsectService.getInsectList(request);
        return R.ok(warningInsects);
    }


    @ApiOperation("查询昆虫历史识别分析数据")
    @GetMapping("/getInsectAnalysisCountVO")
    public R<InsectAnalysisCountVO> getInsectAnalysisCountVO(InsectListRequest request)
    {
        InsectAnalysisCountVO vo = insectSituationService.getInsectAnalysisCountVO(request);
        return R.ok(vo);
    }

    @ApiOperation("首页-统计账号下识别虫数量")
    @GetMapping("/getUserInsectCountData")
    public R<HearderInsectVO> getUserInsectCountData(InsectCountDataRequest request)
    {
        HearderInsectVO countData = insectSituationService.getUserInsectCountData(request);
        return R.ok(countData);
    }

    @ApiOperation("数据分析 - 查询某一类虫的图片")
    @ApiImplicitParams({  @ApiImplicitParam(name = "deviceId",value = "设备编号") ,
            @ApiImplicitParam(name = "time",value = "日期 格式 yyyy-MM-dd", required = true) ,
            @ApiImplicitParam(name = "insectName",value = "昆虫名字", required = true)})
    @GetMapping("/getByInsectName")
    public R<List<DevicePhotoVO>> getByInsectName(String deviceId, @RequestParam String time, @RequestParam String insectName)
    {
        List<DevicePhotoVO> vos = insectSituationService.getByInsectName(deviceId, time, insectName);
        return R.ok(vos);
    }

    @ApiOperation("根据设备编号获取传感器因子")
    @ApiImplicitParams({@ApiImplicitParam(name = "deviceIds",value = "设备编号, 多个用逗号隔开")})
    @GetMapping("/getFactorById")
    public R<List<FactorInfo>> getFactorById(String deviceIds)
    {
        List<FactorInfo> factorInfos = insectSituationService.getFactorById(deviceIds);
        return R.ok(factorInfos);
    }

    @ApiOperation("根据用户下的传感器因子")
    @ApiImplicitParams({@ApiImplicitParam(name = "deviceIds",value = "设备编号, 多个用逗号隔开")})
    @GetMapping("/getFactorByUser")
    public R<List<FactorInfo>> getFactorByUser()
    {
        List<FactorInfo> factorInfos = insectSituationService.getFactorByUser();
        return R.ok(factorInfos);
    }

    @ApiOperation("根据因子名查询用户的设备")
    @ApiImplicitParams({@ApiImplicitParam(name = "factorName",value = "因子名称")})
    @GetMapping("/getDeviceByFactor")
    public R<List<DeviceInfo>> getDeviceByFactor(String factorName)
    {
        List<DeviceInfo> factorInfos = insectSituationService.getDeviceByFactor(factorName);
        return R.ok(factorInfos);
    }

    @ApiOperation("数据分析 - 多台多因子")
    @PostMapping("/getFactorData")
    public R<List<DeviceFactorDataVO>> getFactorData(@RequestBody DeviceFactorDataRequest request)
    {
        List<DeviceFactorDataVO> vos = insectSituationService.getFactorData(request);
        return R.ok(vos);
    }

    @ApiOperation("数据分析 - 多台单因子(风吸 - 基础数据)")
    @PostMapping("/getBaseData")
    public R<List<DeviceFactorDataVO>> getBaseData(@RequestBody DeviceFactorDataRequest request)
    {
        List<DeviceFactorDataVO> vos = insectSituationService.getBaseData(request);
        return R.ok(vos);
    }


    @ApiOperation("数据分析 - 导出 - 多台单因子(风吸 - 基础数据)")
    @PostMapping("/exportBaseData")
    public R<String> exportBaseData(@RequestBody DeviceFactorDataRequest request)
    {
        String result = insectSituationService.exportBaseData(request);
        return R.ok(result);
    }


    @ApiOperation("数据分析 - 查询风吸杀虫灯列表")
    @PostMapping("/getFxDevice")
    public R<List<DeviceInfo>> getFxDevice()
    {
        DeviceInfoRequest request = new DeviceInfoRequest();
        request.setProductId("136,47"); //风吸杀虫灯产品id
        IPage<DeviceInfo> page = deviceInfoService.queryPage(request);
        List<DeviceInfo> records = page.getRecords();
        return R.ok(records);
    }

    @ApiOperation("数据分析 - 综合分析对比数据")
    @PostMapping("/getContrastData")
    public R<DeviceContrastDataVO> getContrastData(@RequestBody DeviceFactorDataRequest request)
    {
        DeviceContrastDataVO vos = insectSituationService.getContrastData(request);
        return R.ok(vos);
    }

    @ApiOperation("数据分析 - 综合分析对比数据 - 新")
    @PostMapping("/getContrastDeviceData")
    public R<DeviceContrastDataVO> getContrastDeviceData(@RequestBody DeviceFactorDataRequest request)
    {
        DeviceContrastDataVO vos = insectSituationService.getContrastData(request);
        return R.ok(vos);
    }

}
